package multiThread.pojo;

/**
 * @projectName: java-sample
 * @description:
 * @author: Adam
 * @create: 2019-12-30 18:46
 **/

public class Account {

    //封装账户编号、账户余额
    private String accountNo;

    private int balance;

    //空构造器
    public Account(){}

    public Account(String accountNo,int balance){
        this.accountNo = accountNo;
        this.balance = balance;
    }

    public String getAccountNo() {
        return accountNo;
    }

    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public int getBalance() {
        return balance;
    }

    public void setBalance(int balance) {
        this.balance = balance;
    }


    public int hashCode(){
        return accountNo.hashCode();
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj !=null && obj.getClass() == Account.class){

            /**
             * java类型强转的场景
             *  1. 直接关系
             *     继承父类或实现了接口,父类转子类需要强转
             *  2. 间接关系
             *      对基本类型而言，强转意味着“砍掉”部分内容，谁的精度高，范围广，转成精度低，范围小的就要强转。
             *      double >>float >>int 强转。 long>>int >> short 强转，砍掉。
             */
            Account target = (Account) obj;
            return target.getAccountNo().equals(accountNo);
        }
        return false;

    }
}
